package org.ellwood.core.utils;

import org.ellwood.core.common.entity.socket.SocketBean;
import org.ellwood.core.common.entity.TransferMessage;

import java.util.List;

/**
 * @ProjectName: ellwood-boot-pro
 * @PackageName: org.ellwood.core.utils
 * @ClassName: SocketUtil
 * @Description: // socket工具类
 * @Author: Ellwood
 * @CreateDate: 2024/6/14 - 下午4:29
 * @Version: V1.0.0
 */
public class SocketUtil {

    public static SocketBean<?> formatSocketMessage(String message){
        return JsonUtils.parseObject(message,SocketBean.class);
    }

    public static String transferMessage(SocketBean<?> bean){
        return JsonUtils.toJsonString(bean);
    }

    /**
     * 发送消息转换
     * @param socketBean 消息体bean
     * @param username 名称集合
     * @return 返回结果
     */
    public static TransferMessage pubTransferMessage(SocketBean<?> socketBean, List<String> username){
        TransferMessage transferMessage = new TransferMessage();
        transferMessage.setMessage(socketBean);
        transferMessage.setToUsers(username);
        return transferMessage;
    }

}
